<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('添加文档文件')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-pdf-add">
            <div class="form-group">
                <label class="col-sm-2 control-label is-required">标题：</label>
                <div class="col-sm-9">
                    <input name="title" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">描述：</label>
                <div class="col-sm-9">
                    <input name="pdfDescribe" class="form-control" type="text">
                </div>
            </div>
<!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label">文件路径：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="pdfFilepath" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <input type="hidden" name="pdfFilepath" id="hfile"/>
            <div class="form-group">
                <label class="col-sm-2 control-label">文件</label>
                <div class="col-sm-9">
                    <label class="font-noraml">上传文件</label>
                    <div class="file-loading">
                        <input id="fileinput" type="file" multiple>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">类型：</label>
                <div class="col-sm-9">
                    <select name="pdfType" class="form-control m-b" th:with="type=${@dict.getType('business_pdf_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
        var prefix = ctx + "pdf/pdf"
        $("#form-pdf-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                let fileval = $("#hfile").val();
                if(fileval == "" || fileval == null){
                    $.modal.alertWarning('请先添加一个文件！')
                    return;
                }
                $.operate.save(prefix + "/add", $('#form-pdf-add').serialize());
            }
        }

        $(document).ready(function () {
            $("#fileinput").fileinput({
                uploadUrl:"/businessfile/file/addfile",
                uploadAsync:true,
                maxFileCount:1,
                dropZoneTitle:"拖拽文件到这里...<br/>最大文件体积25MB"
            });

            $("#fileinput").on("fileuploaded", function (event, data, previewId, index) {
                console.log(data);
                $("#hfile").val(data.response.data);
            })

        });
    </script>
</body>
</html>
